#include <bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
int _,n,m;
int a[200005];
map<int,int> tim;
signed main() {
    for(scanf("%lld",&_);_;--_) {
        tim.clear();
        scanf("%lld%lld",&n,&m);
        int row=0,mx=0,mxid=0;
        rep(i,1,n) {
            scanf("%lld",&a[i]);
            row+=a[i];
            if(row>mx) mx=row,mxid=i,tim[mx]=i;
        }
        rep(i,1,m) {
            int x;
            scanf("%lld",&x);
            map<int,int>::iterator ii=tim.lower_bound(x);
            if(ii==tim.end()&&row<=0) {printf("-1 ");continue;}
            else if(ii==tim.end()){
                map<int,int>::iterator lst=tim.end();--lst;
                int ned=(x-lst->first+row-1)/row;
                ii=tim.lower_bound(x-ned*row);
                printf("%lld ",ii->second+ned*n-1);
            } else {
                printf("%lld ",ii->second-1);
            }
        }
        puts("");
    }
    return 0;
}
